<template>
	<view class="page savepadding">
		<view class="card box1">
			<view class="card-box">
				<view class="card-title">
					<view class="title1">{{filterNull(schemeData.brandName)+" "+filterNull(schemeData.seriesName)}}</view>
					<view class="desc">{{filterNull(schemeData.modelName)}}</view>
				</view>
				           
				<view class="card-img">
					<image :src="imgUrl" mode="aspectFill"></image>
				</view>
			</view>
			
		</view>
		<view class="card">
			<view class="title">租赁信息</view>
			<view class="list inline">
				<view class="label">城市<text style="color:#FF6A15 ">*</text></view>
				<!-- <view class="text">{{formData.rentType|rentTypeText}}</view> -->
				<view class="text">{{filterNull(schemeData.city)}}</view>
			</view>
			<view class="line"></view>
			<view class="list inline">
				<view class="label">出租方<text style="color:#FF6A15 ">*</text></view>
				<view class="text">{{filterNull(schemeData.storeName)}}</view>
			</view>
			<view class="line"></view>
			<view class="list inline">
				<view class="label">租赁方式<text style="color:#FF6A15 ">*</text></view>
				<view class="text">{{filterNull(schemeData.schemeTypeStr)}}</view>
			</view>
			<view class="line"></view>
			<view class="list inline">
				<view class="label">租赁时长<text style="color:#FF6A15 ">*</text></view>
				<view class="text">{{filterNull(schemeData.schemeTime)}}期</view>
			</view>
		</view>
		<view class="card">
			<view class="title">付款方式</view>
			<view class="button-wrap">
				<view class="button" :class="{active:formData.paymentMethod==1, disable:!verifyTotalPrice(1)}"
					@click="setPaymentMethod(1)">按月支付</view>
				<!-- <view class="button" :class="{active:formData.paymentMethod==2, disable:!verifyTotalPrice(2)}"
					@click="setPaymentMethod(2)">两月支付</view> -->
				<view class="button" :class="{active:formData.paymentMethod==3, disable:!verifyTotalPrice(3)}"
					@click="setPaymentMethod(3)">季度支付</view>
				<view class="button" :class="{active:formData.paymentMethod==6, disable:!verifyTotalPrice(6)}"
					@click="setPaymentMethod(6)">半年支付</view>
				<view class="button" :class="{active:formData.paymentMethod==4, disable:!verifyTotalPrice(4)}"
					@click="setPaymentMethod(4)">按年支付</view>
				<view class="button" :class="{active:formData.paymentMethod==5, disable:!verifyTotalPrice(5)}"
					@click="setPaymentMethod(5)">一次性支付</view>
			</view>
			<view class="line1"></view>
			<view class='total-box'>
				<view class="total" style="display:flex;margin-bottom: 32upx;justify-content: space-between;">
					<view>
						<text class='total-text'>
							首期付款
						</text>
					</view>
					<view style="display: flex;">
						<text class='total-money'>￥{{totalPrice}}</text>
						<u-icon name="arrow-right" @click="showfeiyong1=true"></u-icon>
					</view>	
				</view>
				<view class="total" style="display:flex;margin-bottom: 32upx;justify-content: space-between;">
					<view>
						<text class='total-text'>
							总合计
						</text>
					</view>
					<view style="display: flex;">
						<text class='total-money'>￥{{fullPaymentShow.fullPayment}}</text>
						<u-icon name="arrow-right" @click="showfeiyong2=true"></u-icon>
					</view>
					
				</view>
			</view>
			
		</view>
		<view class="card" style='padding:0 32upx'>
			<view class='order-sty'>
				<view class="order-title">订单备注</view>
				<view v-if="!showCoupon" class="order-value">
					<u-input v-model="formData.orderDesc" type="textarea" :border="false" :auto-height="true" placeholder="请输入备注信息" />
				</view>
			</view>
			
		</view>
		<!-- #ifndef H5 -->
		<!-- <view class="card" @click="onClickYouhui">
			<view class="coupon">
				<view>
					<text class='coupon-text'>优惠券</text>
				</view>
				<view class='money-box'>
					<text class='coupon-money' v-if='schemeData.money'>{{schemeData.couponName}}-￥{{schemeData.money}}</text>
					<text class='coupon-money' v-else>请选择优惠券</text>
					<u-icon name="arrow-right" color="#333" size="12" />
				</view>
				
			</view>
		</view> -->
		<!-- #endif -->
		<view class="total" style="display:flex;justify-content: space-between;">
			<view>
				<text class='total-money-tit'>付款金额</text>
				
			</view>
			<view style="display:flex;">
				<text class='total-money-value'>￥{{shijifukuan}}</text>
				<u-icon name="arrow-right" @click="showfeiyong=true"></u-icon>
			</view>
			
		</view>
		<view class="total" style="display:flex;" v-if="formData.couponValue">共省￥{{formData.couponValue}}</view>
		<view style="height:60px"></view>
		<!-- 按钮区 -->
		<view class='button-box'>
			<view class="bottom_btns savepadding" :class="isIos?'bottom3':''">
			    <view class="button" @click="pre">上一步</view>
			    <view class="button" @click="onShowSubmitModel">{{formData.repaymentMethod==2?'提交订单':'立即支付'}}</view>
			</view>
			
		</view>
		<!-- 优惠券弹窗 -->
		<!-- <u-popup safeAreaInsetTop mode="bottom" :show="showCoupon" round="10" closeable @close="showCoupon=false">
			<CouponList v-if="showCoupon" :schemeTypeStr="schemeData.schemeTypeStr" :coupon="couponData"
				:rentType="formData.rentType" :carModelId="formData.carModelId" :feeItems="formData.feeItems"
				@selected="onCouponSelected"></CouponList>
		</u-popup> -->
		<u-popup :show="showCoupon" mode="bottom" round="10" style="position: relative;z-index:1;">
			<view class='info-box' style='height:800upx'>
				<view class='title-box'>
					<view class='title-box-text'>优惠券</view>
					<view class="close-img-box" @click='showCoupon = false'>
						<image class="close-img" src="../../static/window_icon_close.png"></image>
					</view>
					
				</view>
				<view style='margin-bottom: 100upx;height: 900upx;overflow-y: auto;' v-if='couponList.length>0'>
					<view v-for="(item, index) in couponList" :key="item.index" style="height: 216upx;width:100%;margin-bottom:14upx">
							<coupon-cell
							:businessId="item.businessId"
							:discountAmount="item.money"
							:rangInfo="item.conditionMoney"
							:activityType="item.couponName"
							:durationDate="item.useTime"
							:couponType="item.businessName"
							:storeRang = "item.applicableUnit"
							:useNotice="item.useNotice"
							:businessType="1"
							:memberCouponStatus="item.memberCouponStatus"
							:isReceive="1"
							:isTurn="item.isTurn"
							:memberId="item.memberId"
							:useTypeName="item.useTypeName"
							:applicableUnitType="item.applicableUnitType"
							:objData="item"
							@shareCoupon="shareCoupon"
							@getCoupon="getCoupon"
							:isAleart='true'
							></coupon-cell>
					</view>
				</view>
				<view style='margin-bottom: 100upx;height: 900upx;overflow-y: auto;' v-else>
					<no-data content='暂无优惠券'></no-data>
				</view>
				<view style='position:absolute;bottom: 0upx;width: 100%;height: 32upx;background-color: #ffffff;'>
					<!-- <view class="bottom2" :class="isIos?'bottom3':''" @click='couponCommit()'>确定</view> -->
				</view>
				
			</view>
		</u-popup>
		<!-- 提交订单提示 -->
		<u-modal :show="showSubmitModal" :title-style="{'color':'#000000'}" :cancel-style="{'color':'#173B42'}" title="提交订单" :showCancelButton="true" :asyncClose="true" @confirm="submitOrder"
			@cancel="showSubmitModal=false">
			<view class="modal-text">是否提交订单</view>
		</u-modal>
		<!-- 费用信息弹窗1 -->
		<u-popup :show="showfeiyong1" mode="bottom" round="10" style="position: relative;">
			<view class='info-box'>
				<view class='title-box'>
					<view class='title-box-text'>首期付款金额明细说明</view>
					<view class="close-img-box" @click='costCommit(1)'>
						<image class="close-img" src="../../static/window_icon_close.png"></image>
					</view>
					
				</view>
				<view style='margin-bottom: 100upx;'>
					<view v-for="(item,index) in formData.feeItems" class='info-value' :key='index'>
						<view class='info-value-text'>{{item.type|feiyongFilter}}/元：</view>
						<view class='info-value-money'>￥{{item.amount}}</view>
					</view>
					<view class='info-value'>
						<view class='info-value-text'>月租金*{{formData.paymentMethod|zhifufangshiFilter2(formData.tenancy)}}期</view>
						<view class='info-value-money'>￥{{fullPaymentShow.monthly_rent}}</view>	
					</view>
				</view>
				
				<view class="bottom2" :class="isIos?'bottom3':''" @click='costCommit(1)'>确定</view>
			</view>
		</u-popup>
		<!-- 费用信息弹窗2 -->
		<u-popup :show="showfeiyong2" mode="bottom" round="10" style="position: relative;">
			<view class='info-box'>
				<view class='title-box'>
					<view class='title-box-text'>总金额明细说明</view>
					<view class="close-img-box" @click='costCommit(2)'>
						<image class="close-img" src="../../static/window_icon_close.png"></image>
					</view>
					
				</view>
				<view style='margin-bottom: 100upx;'>
					<view v-for="(item,index) in fullPaymentShow.feeItems" class='info-value' :key='index'>
						<view class='info-value-text'>{{item.type|feiyongFilter}}/元：</view>
						<view class='info-value-money'>￥{{item.amount}}</view>
					</view>
					<view class='info-value'>
						<view class='info-value-text'>月租金*{{formData.tenancy}}期</view>
						<view class='info-value-money'>￥{{fullPaymentShow.total}}</view>	
					</view>
				</view>
				
				<view class="bottom2" :class="isIos?'bottom3':''" @click='costCommit(2)'>确定</view>
			</view>
		</u-popup>
		<!-- 费用信息弹窗 -->
		<u-popup :show="showfeiyong" mode="bottom" round="10" style="position: relative;">
			<view class='info-box'>
				<view class='title-box'>
					<view class='title-box-text'>付款金额明细说明</view>
					<view class="close-img-box" @click='costCommit(3)'>
						<image class="close-img" src="../../static/window_icon_close.png"></image>
					</view>
					
				</view>
				<view style='margin-bottom: 100upx;'>
					<view v-for="(item,index) in formData.feeItems" class='info-value' :key='index'>
						<view class='info-value-text'>{{item.type|feiyongFilter}}/元：</view>
						<view class='info-value-money'>￥{{item.amount}}</view>
					</view>
					<view class='info-value'>
						<view class='info-value-text'>月租金*{{formData.paymentMethod|zhifufangshiFilter2(formData.tenancy)}}期</view>
						<view class='info-value-money'>￥{{fullPaymentShow.monthly_rent|| 0}}</view>	
					</view>
					<!-- #ifndef H5 -->
					<!-- <view class='info-value'>
						<view class='info-value-text'>优惠券抵扣金额/元：</view>
						<view class='info-value-money'>￥{{schemeData.money|| 0}}</view>	
					</view> -->
					<!-- #endif -->
				</view>
				
				<view class="bottom2" :class="isIos?'bottom3':''" @click='costCommit(3)'>确定</view>
			</view>
		</u-popup>
		<u-popup :show="showCondition" mode="bottom" round="10" style="position: relative;">
			<view class='info-box'>
				<view class='title-box'>
					<view class='title-box-text'>请选择还款日期</view>
					<view class="close-img-box" @click='showCondition=false'>
						<image class="close-img" src="../../static/window_icon_close.png"></image>
					</view>
					
				</view>
				<view style='margin-bottom: 100upx;max-height: 400upx;overflow-y: auto;'>
					<view v-for="(item,index) in days" class='info-value' @click=typeClick(item) :key='index'>
						<view class='info-value-text'>每月{{item}}日</view>
						<view class='iclose-img-box' v-if="typeValue==item">
							<image class="close-img" src="../../static/window_icon_right.png"></image>
						</view>
					</view>
				</view>
				<view style='position:absolute;bottom: 0upx;width: 100%;height: 200upx;background-color: #ffffff;'>
					<view class="bottom2" :class="isIos?'bottom3':''" @click='confirm()'>确定</view>
				</view>
				
			</view>
		</u-popup>
		<!-- 登录弹窗 -->
		<!-- <LoginMask></LoginMask> -->
	</view>
</template>

<script>
	import sumBy from 'lodash/sumBy';
	import reduce from 'lodash/reduce';
	import isEmpty from 'lodash/isEmpty';
	import * as orderApi from '@/common/apis/order-api';
	import LoginMask from '@/components/layout/login-mask.vue';
	import CouponList from './components/coupon-list.vue';
	import xieyi from './components/xieyi.vue';
	import moment from '@/util/moment.js'
	import * as relaNameApi from '@/common/apis/relaName-api';
	import couponCell from '../../components/coupon/coupon-cell.vue'
	import {
	    schemeinfo,selectMyCouponByScheme
	} from '@/common/api.js';

	export default {
		components: {
			LoginMask,
			CouponList,
			xieyi,
			couponCell
		},
		filters: {
			rentTypeText(rentType) {
				// 租赁类型：1、经租 2、以租代购 3、展示车 4、试用车 5、融租 6、直购
				return {
					1: "经租",
					2: "以租代购",
					3: "展示车",
					4: "试用车",
					5: "融租",
					6: "直购",
				} [rentType];
			},
			feiyongFilter(val) {
				return {
					deposit: '保证金',
					servicingFee: '整备费',
					downPayment: '首付款',
					monthlyRent: '月租',
					balance: '尾款',
					advanceDeposit: '定金',
					coverCharge: '服务费',
				} [val];
			},
			zhifufangshiFilter(val) {
				return {
					1: '月付',
					2: '两月付',
					3: '季度',
					4: '年付',
					5: '一次性结清',
					6: '半年付',
				} [val];
			},
			zhifufangshiFilter2(val, tenancy) {
				return {
					1: 1,
					2: 2,
					3: 3,
					4: 12,
					5: tenancy,
					6: 6,
				} [val];
			},
		},
		data() {
			return {
				typeValue:'',
				showCondition:false,
				imgUrl:'',
				showfeiyong1: false,
				showfeiyong2: false,
				showfeiyong: false,
				showSubmitModal: false,
				showCoupon: false,
				orderConfValue: 1, // 值为1时才显示代扣和微信支付
				daikouflag: 2, // 是否开通代扣1.开通 2.未开通
				couponData: {}, // 优惠券数据
				formData: {
					cavanFlag:'',
					vehicleAge:'', // 车龄
					schemeType:'',
					deptId:uni.getStorageSync('storeId'),
					orderPaymentId: "", // 支付订单id（repaymentMethod为1时必传）
					carModelId: "", // 车型id
					rentType: 1, // 租赁类型：1、经租 2、以租代购 3、展示车 4、试用车 5、融租 6、直购
					repaymentMethod: 2, // 还款方式：1.微信,2、其他，3、代扣
					paymentDayType: 1, // 每期还款日期：1、付款日与交车日一致 2、选择付款日
					paymentDay: 1, // 付款日（paymentDayType为2时必传，范围1-31正整数）
					orderDesc: "", // 订单备注（可以为空）
					paymentMethod: 5, // 付款方式 1、月付 2、两月付 3、季度 4、年付 5、一次性结清 6半年付
					tenancy: 36, // 租期
					couponNo: "", // 优惠券编号（可以为空）
					couponFaceValue: "", // 优惠券面额（可以为空）
					couponUseValue: "", // 优惠券使用金额（可以为空）
					couponValue: "", // 优惠券金额（可以为空）
					couponType: "", // 优惠券类型（可以为空）
					couponData: "", // 优惠券数据（可以为空）
					subSchemeId: "", // 子方案id
					feeItems: [ //费用项
						{
							amount: "", // 金额
							type: "", // 费用类型:
							// cash_deposit 保证金
							// servicing_fee 整备费
							// down_payment 首付款
							// monthly_rent 月租
							// balance_payment 尾款
							// advance_deposit 定金
							// cover_charge 服务费
						},
					]
				},
				isSigned: false, // 是否已签约
				isFirstSigned: false, // 是否首次签约
				oneSignedBank: {
					cardImgFront: "", // 银行卡正面
					cardImgBack: "", // 银行卡背面
					mobileNo: "", // 手机号
					bankCardNo: "", // 银行卡号
					bankDeposit: "" // 开户行
				},
				schemeData: {
					brandName: '',
					schemeId: '',
					seriesName: '',
					modelName: '',
					schemeTypeStr: '',
					schemeType: 0, //1.直购，2分期购车，3租赁 4.金融分期
					dataList: [],
					selectItem: 0,
					couponName:'',
					money:'',
				},
				monthly_rent: 0,
				isDate: false, // 是否按日期支付
				nextPage: 1, // 订单提交成功页面的选择
				isIos:false,
				couponInfo:{},
				couponSelectInfo:{},
				couponList:[] , // 优惠卷列表
				shijifukuan:'',
			};
		},
		computed: {
			openid() {
				return this.$store.state.user.openid;
			},
			days() {
				return 	[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
						28, 29, 30, 31]
					// [1, 5, 10, 15, 20, 25],
			},
			
			// 全款展示
			fullPaymentShow() {
				// 月租金
				const monthly_rent = this.monthly_rent;
				// 租期
				const tenancy = this.formData.tenancy;
				// 总杂费
				const total = sumBy(this.formData.feeItems, val => val.amount) - monthly_rent;
				// 全款
				let fullPayment = total + (monthly_rent * tenancy);
				fullPayment = ((fullPayment * 100) / 100).toFixed(2)
				return {
					monthly_rent: Number(this.totalPrice - total).toFixed(2), // 净月费
					total: Number(tenancy * monthly_rent).toFixed(2), // 总月费
					feeItems: this.formData.feeItems, // 费用项
					fullPayment, // 全款
				};
			},
			// 总合计
			totalPrice() {
				// 月租金
				const monthly_rent = this.monthly_rent;
				console.log(monthly_rent,'monthly_rentmonthly_rentmonthly_rent')
				// 总杂费
				const total = sumBy(this.formData.feeItems, val => val.amount) - monthly_rent;
				console.log(total,'totaltotaltotal')
				// 租期
				const tenancy = this.formData.tenancy;
				console.log(tenancy,'tenancytenancytenancytenancy')
				// 分期支付方式
				const paymentMethod = this.formData.paymentMethod;
				console.log(paymentMethod,'paymentMethodpaymentMethodpaymentMethod')
				// 全款
				let fullPayment = total + (monthly_rent * tenancy);
				fullPayment = ((fullPayment * 100) / 100).toFixed(2)
				console.log(fullPayment,'fullPaymentfullPaymentfullPayment')
				// 最终抛出金额方法
				const output = (_payment) => {
					const amount = _payment <= fullPayment ? _payment : fullPayment;
					// // 如果使用了优惠券
					// if (Number(this.formData.couponValue) > 0) {
					//     return amount - Number(this.schemeData.money); // 减去优惠券金额
					// }
					return ((amount * 100) / 100).toFixed(2)
				};
				
				// 一次性付清
				if (paymentMethod == 5) {
					// #ifdef H5
						this.shijifukuan = fullPayment;
					// #endif
					// #ifndef H5
						this.shijifukuan = fullPayment - Number(this.schemeData.money);
					// #endif
					return fullPayment;
				}
				// 月付
				if (paymentMethod == 1) {
					// #ifdef H5
						this.shijifukuan = output(total + monthly_rent)
					// #endif
					// #ifndef H5
						this.shijifukuan = output(total + monthly_rent) - Number(this.schemeData.money);
					// #endif
					
					return output(total + monthly_rent);
				}
				// 两月付
				if (paymentMethod == 2) {
					// #ifdef H5
						this.shijifukuan = output(total + (monthly_rent * 2));
					// #endif
					// #ifndef H5
						this.shijifukuan = output(total + (monthly_rent * 2)) - Number(this.schemeData.money);
					// #endif
					
					return output(total + (monthly_rent * 2));
				}
				// 季付
				if (paymentMethod == 3) {
					// #ifdef H5
						this.shijifukuan = output(total + (monthly_rent * 3));
					// #endif
					// #ifndef H5
						this.shijifukuan = output(total + (monthly_rent * 3)) - Number(this.schemeData.money);
					// #endif
					
					return output(total + (monthly_rent * 3));
				}
				// 半年付
				if (paymentMethod == 6) {
					// #ifdef H5
						this.shijifukuan = output(total + (monthly_rent * 6));
					// #endif
					// #ifndef H5
						this.shijifukuan = output(total + (monthly_rent * 6)) - Number(this.schemeData.money);
					// #endif
					return output(total + (monthly_rent * 6));
				}
				// 年付
				if (paymentMethod == 4) {
					// #ifdef H5
						this.shijifukuan = output(total + (monthly_rent * 12));
					// #endif
					// #ifndef H5
						this.shijifukuan = output(total + (monthly_rent * 12)) - Number(this.schemeData.money);
					// #endif
					return output(total + (monthly_rent * 12));
				}
			},
			// 实际付款金额
			shijifukuan() {
				const total = this.totalPrice - Number(this.formData.couponValue);
				return Math.ceil(total * 100) / 100;
			},
			payFormData() {
				return {
					paymentMethod: this.formData.paymentMethod, // 付款方式 1、月付 2、两月付 3、季度 4、年付 5、一次性结清 6半年付
					tenancy: this.formData.tenancy, // 租期
					couponNo: this.formData.couponNo, // 优惠券编号（可以为空）
					couponFaceValue: this.formData.couponFaceValue, // 优惠券面额（可以为空）
					couponUseValue: this.formData.couponUseValue, // 优惠券使用金额（可以为空）
					couponValue: this.formData.couponValue, // 优惠券金额（可以为空）
					couponType: this.formData.couponType, // 优惠券类型（可以为空）
					couponData: this.formData.couponData, // 优惠券数据（可以为空）
					feeItems: this.formData.feeItems,
					
				};
			},
		},
		onLoad(option) {	
			this.schemeData = JSON.parse(option.data);
			this.schemeData.couponName = ''
			this.schemeData.money = ''
			this.formData.schemeType = this.schemeData?.schemeType
			this.formData.vehicleAge = this.schemeData?.dataList[this.schemeData.selectItem]?.vehicleAge
			this.formData.cavanFlag = this.schemeData?.cavanFlag
			console.log(this.schemeData,1111111111111)
			schemeinfo({
				params: {
					subSchemeId: this.schemeData.subSchemeId,
					subSchemeRentId: this.schemeData.subSchemeRentId,
					cityCode: uni.getStorageSync('cityCode')	
				}
			}).then((res)=>{
				this.imgUrl = res.carModelUrlList[0]
			})
			selectMyCouponByScheme({
				params: {
					schemeId: this.schemeData.schemeId,
					subSchemeId: this.schemeData.subSchemeId,
					subSchemeRentId: this.schemeData.subSchemeId,
					storeId: uni.getStorageSync('storeId')
				}
			}).then((res)=>{
				this.couponList = res
			})
			const feeItems = this.schemeData.dataList[this.schemeData.selectItem]; // 选择方案
			this.formData.carModelId = this.schemeData.modelId; // 车型id
			const rentType = {
				1: 6,
				2: 2,
				3: 1,
				4: 5,
			};
			this.formData.rentType = rentType[this.schemeData.schemeType]; // 租赁类型：1、经租 2、以租代购 3、展示车 4、试用车 5、融租 6、直购
			this.formData.tenancy = feeItems?.tenancy; // 租期
			this.formData.subSchemeId = feeItems?.subSchemeId; // 子方案id
			const keyMap = {};
			this.formData.feeItems = reduce(feeItems, (pv, v, k) => {
				if (v) {
					if (k == 'monthlyRent') {
						this.monthly_rent = v
					}
					//  经租只有月租和保证金和服务费
					if (this.formData.rentType == 1 && (k == 'monthlyRent' || k == 'deposit' || k ==
						'coverCharge')) {
						pv.push({
							amount: v,
							type: k,
						});
					}
					// 以租代购月租整备费和尾款
					if (this.formData.rentType == 2 && (k == 'monthlyRent' || k == 'servicingFee' || k ==
							'balance' || k == 'downPayment')) {
						pv.push({
							amount: v,
							type: k,
						});
					}
					// 融租月租首付款和尾款
					if (this.formData.rentType == 5 && (k == 'monthlyRent' || k == 'downPayment' || k ==
						'balance')) {
						pv.push({
							amount: v,
							type: k,
						});
					}
				}
				console.log(pv,'pvpvvpp')
				return pv
			}, []); //费用项
		},
		async onShow() {
			const type = uni.getStorageSync('modelType')
			if(type=='iphone'){
				this.isIos = true
			}else{
				this.isIos = false
			}
		},
		methods: {
			shareCoupon(){},
			getCoupon(info){
				this.schemeData.couponName=info.couponName
				this.schemeData.money=info.money
				this.formData.couponValue = info.money
				this.shijifukuan = this.totalPrice - Number(info.money);
				this.couponSelectInfo = info
				console.log(info,111111111)
				this.formData.couponNo = info.memberId || ""; // 优惠券编号（可以为空）
				this.formData.couponFaceValue = info.money || ""; // 优惠券面额（可以为空）
				this.formData.couponUseValue = info.conditionMoney || ""; // 优惠券使用金额（可以为空）
				this.formData.couponValue = info.money || ""; // 优惠券金额（可以为空）
				this.formData.couponType = info.useTypeNo || ""; // 优惠券类型（可以为空）
				this.formData.couponData = info.preferentialInfo || ""; // 优惠券数据（可以为空）
				this.showCoupon = false
			},
			confirm(){
				this.showCondition = false
			},
			typeClick(info){
				this.formData.paymentDay = info
				this.typeValue = info
			},
			costCommit(type){
				if(type==1){
					this.showfeiyong1 = false
				}else if(type==2){
					this.showfeiyong2 = false
				}else if(type==3){
					this.showfeiyong = false 
				}
				
			},
			/**
			 * 选择优惠券
			 */
			async onCouponSelected(item) {
				this.formData.couponNo = item.memberId || ""; // 优惠券编号（可以为空）
				this.formData.couponFaceValue = item.money || ""; // 优惠券面额（可以为空）
				this.formData.couponUseValue = item.conditionMoney || ""; // 优惠券使用金额（可以为空）
				this.formData.couponValue = item.money || ""; // 优惠券金额（可以为空）
				this.formData.couponType = item.useTypeNo || ""; // 优惠券类型（可以为空）
				this.formData.couponData = item.preferentialInfo || ""; // 优惠券数据（可以为空）
				this.couponData = item; // 暂存优惠券数据
				// this.showCoupon = false; // 关闭优惠券弹窗
			},
			// 优惠卷选择
			onCouponSelecteds(info){
				this.couponInfo = info
			},
			// 优惠卷确定
			couponCommit(){
				this.formData.couponNo = this.couponInfo.memberId || ""; // 优惠券编号（可以为空）
				this.formData.couponFaceValue = this.couponInfo.money || ""; // 优惠券面额（可以为空）
				this.formData.couponUseValue = this.couponInfo.conditionMoney || ""; // 优惠券使用金额（可以为空）
				this.formData.couponValue = this.couponInfo.money || ""; // 优惠券金额（可以为空）
				this.formData.couponType = this.couponInfo.useTypeNo || ""; // 优惠券类型（可以为空）
				this.formData.couponData = this.couponInfo.preferentialInfo || ""; // 优惠券数据（可以为空）
				this.couponData = this.couponInfo; // 暂存优惠券数据
			},

			async onShowSubmitModel() {
				this.showSubmitModal = true;
			},

			// 提交订单
			async submitOrder() {
				this.showSubmitModal = false;
				this.nextPage = 1;
				this.submitOrderHandle();
			},
			async submitOrderHandle() {
				try {
					uni.showToast({
						title: '订单提交中...',
						icon: 'loading'
					});
					const result = await orderApi.submitOrder(this.formData);

					this.recordOrder(result);
						uni.reLaunch({
							url: `/pages/confirm_order/order-paySuccess?totalPrice=${this.totalPrice}&page=${this.nextPage}`, // 支付成功页面
						})
					return result;
					
				} catch (error) {
					uni.showToast({
						title: error,
						icon: 'error'
					});
				}
			},

			//下单操作记录
			async recordOrder(orderid) {
				let nowTimes = new Date().getTime();

				let duration = Math.round((nowTimes - getApp().globalData.taskStartTime) / 1000);

				//访问
				this.$store.dispatch('home/recordUse', {
					recordType: 4,
					recordOrderId: orderid,
					objRecordData: {
						durationTime: duration,
						recordTime: moment(nowTimes).format('YYYY-MM-DD HH:mm:ss'),
						price: this.shijifukuan,
					}
				})
			},


			pre() {
				uni.navigateBack()
			},

			/**
			 * 设置还款方式
			 */
			setPaymentMethod(paymentMethod) {
				if (this.verifyTotalPrice(paymentMethod)) {
					this.formData.paymentMethod = paymentMethod;
				}
			},

			/**
			 * @param {number} paymentMethod 分期支付方式
			 */
			verifyTotalPrice(paymentMethod) {
				// 月租金
				const monthly_rent = this.monthly_rent;
				// 总杂费
				const total = sumBy(this.formData.feeItems, val => val.amount) - monthly_rent;
				// 租期
				const tenancy = this.formData.tenancy;
				// 全款
				const fullPayment = total + (monthly_rent * tenancy);
				function output(_payment) {
					return _payment <= fullPayment ? true : false;
				};
				// 一次性付清
				if (paymentMethod == 5) {
					return fullPayment;
				}
				// 月付
				if (paymentMethod == 1) {
					return output(total + monthly_rent);
				}
				// 两月付
				if (paymentMethod == 2) {
					return output(total + (monthly_rent * 2));
				}
				// 季付
				if (paymentMethod == 3) {
					return output(total + (monthly_rent * 3));
				}
				// 半年付
				if (paymentMethod == 6) {
					return output(total + (monthly_rent * 6));
				}
				// 年付
				if (paymentMethod == 4) {
					return output(total + (monthly_rent * 12));
				}
			},

			onconfirmData({
				value
			}) {
				this.formData.paymentDay = value[0];
				this.isDate = false;
			},

			onClickYouhui() {
				// uni.showToast({ title: '暂无可用优惠券', icon: 'error' });
				this.showCoupon = true;
			},

			// yuezujisuanqi(monthly_rent){
			//     // 分期支付方式
			//     const paymentMethod = this.formData.paymentMethod;
			// },

		}
	}
</script>
<style lang="scss" scoped>
	.box1{
		background-image: url('../../static/矩形@2x.png');
		background-size: cover;
	}
	.page {
		padding: 32upx;
		padding-bottom: 120upx;
	}
	.modal-text{
		text-align:center;
		color:#000000;
		font-size: 28upx;
	}
	.close-img{
		width:32upx ;
		height:32upx;
	}
	.info-box{
		max-height: 80vh;
		padding:32upx;
		background-color: #F8F8F8 ;
		.bottom2 {
			position:absolute;
			bottom: 30upx;
			width: 90%;
			height: 80upx;
			text-align: center;
			line-height: 80upx;
			background-color: $redec;
			border-radius: 8upx;
			color:#ffffff;
			font-size: 32upx;
		}
		.bottom3{
			position:absolute;
			bottom: 70upx;
		}
		.info-value{
			background-color: #ffffff;
			border-radius: 8upx;
			padding: 32upx;
			height: 40upx;
			display: flex;
			justify-content: space-between;
			border-bottom: 2upx solid #F8F8F8;
			align-items: center;
			font-size:28upx ;
			.info-value-text{
				color:#666666
			}
			.info-value-money{
				color:#FF6A15 
			}
		}
		.line{
			width: 100%;
			height: 2upx;
			background: #F8F8F8;
		}
		.title-box{
			width: 100%;
			display: flex;
			justify-content: space-between;
			margin-bottom: 32upx;
			.title-box-text{
				font-size:32upx ;
				font-weight: bold;
				color:#000000,
				
			}
			.close-img-box{
				width:34upx ;
				height:34upx;
				.close-img{
					width:32upx ;
					height:32upx;
				}
			}
			
		}
	}
	
	.total-money-tit{
		font-size: 32upx;
		font-weight: bold;
		color:#000000;
		margin-right: 10upx;
	}
	.total-money-value{
		font-size: 28upx;
		font-weight: bold;
		color:#FF6A15;
	}
	.card-title {
		font-size: 32upx;
		font-weight: bold;
		margin-bottom: 30upx;
	}
	.radio-box{
		display: flex;
		justify-content: space-between;
		.radio-text{
			color:#666666 ;
			font-size: 28upx;
		}
	}
	.line2{
		margin: 24upx 0;
		border-bottom: 1px solid #F8F8F8;
	}
	.card {
		padding: 32upx;
		margin-bottom: 30upx;
		.coupon{
			display: flex;
			justify-content: space-between;
			.coupon-text{
				font-size:28upx;
				color:#666666;
			}
			.money-box{
				display: flex;
				.coupon-money{
					font-size:28upx;
					color:#000000;
				}
			}
			
		}
		.order-sty{
			display: flex;
			width: 100%;
			height: 104upx;
			align-items: center;
			.order-value{
				flex: 1;
			}
		.order-title{
			color:#666666 ;
			font-size: 28upx;
			margin-right: 48upx;
		}
		}
		.total-box{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			
		}
		.line1 {
			margin-bottom: 30upx;
			border-bottom: 1px dashed #F8F8F8;
		}
		.card-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			.card-title{
				.title1 {
				    font-size: 32upx;
				    font-weight: bold;
				    color: #000000;
				    margin-bottom: 18upx;
				}
				.desc {
				    font-size: 24upx;
				    color: #999999;
				}
			}
			.card-img{
				width:208upx;
				height: 100upx;
				image {
				    width: 100%;
				    height: 100%;
				    border-radius: 10upx;
				}
			}
		}

		.title {
			font-size: 32upx;
			font-weight: bold;
			color: #000000;
			margin-bottom: 40upx;
			
		}

		.line {
			margin-bottom: 30upx;
			border-bottom: 1px solid #F8F8F8;
		}
		

		.list {
			&.inline {
				display: flex;
				justify-content: start;
			}

			.label {
				margin-bottom: 30upx;
				font-size: 28upx;
				color: #666666;
				margin-right:32upx ;
			}

			.text {
				font-size: 28upx;
				font-weight: bold;
				color: #000000;
			}
		}

		.button-wrap {
			display: flex;
			flex-wrap: wrap;
			justify-content: start;

			.button {
				width: 188upx;
				line-height: 64upx;
				text-align: center;
				font-size: 28upx;
				color: #173B42;
				border-radius: 8upx;
				margin-bottom: 20upx;
				background-color:#F7FAFC ;
				&:not(:nth-child(3n + 0)) {
					margin-right: 20upx;
				}

				&.active {
					background: #173B42;
					color: #fff;
				}

				&.disable {
					background: #ddd;
					color: #999;
					border-color: #ddd;
				}
			}
		}
	}

	.total {
		font-size: 56uupx;
		font-weight: bold;
		.total-text{
			color:#666666;
			font-size: 28upx;
			margin-right: 10upx;
		}
		.total-money{
			color:#FF6A15;
			font-size: 28upx;
		}
	}
.button-box{
	position: fixed;
	bottom: 0;
	left:0;
	background-color: #ffffff;
	width: 100%;
	height:200upx;
	z-index:1;
	.bottom_btns {
	    display: flex;
	    justify-content: space-between;
	    align-items: center;
	    text-align: center;
	    position: fixed;
	    bottom: 32upx;
	    left: 0;
	    width: 90%;
		padding:0 32upx;
	    z-index: 10;
	    background: #fff;
	    .button {
	        line-height: 80upx;
			width:328upx;
			height: 80upx;
			border:1px solid #173B42 ;
			border-radius: 8upx;
	    }
	
	    .button:nth-child(1) {
	        background: #fff;
	        color: #173B42;
			margin-right:30upx ;
	    }
	
	    .button:nth-child(2) {
	        background: #173b42;
	        color: #fff;
	    }
	}
	.bottom3{
		position:absolute;
		bottom: 70upx;
	}
}


	.blank-detail {
		font-size: 28upx;
		margin-right: 16upx;
		margin-bottom: 16upx;
		color: #333;
	}
</style>
